home *** CD-ROM | disk | FTP | other *** search
/ No Fragments Archive 12: Textmags & Docs / nf_archive_12.iso / MAGS / SOURCES / ATARI_SRC.ZIP / atari source / AHDI / IDEINST / STRING.C < prev    next >
Encoding:
C/C++ Source or Header  |  2001-02-09  |  1.6 KB  |  117 lines

  1. /* string.c */
  2. /* $Header: string.c,v 1.1 86/05/29 12:13:04 dyer Exp $ */
  3.  
  4. /*
  5.  *
  6.  *    string -- handy string functions
  7.  *
  8.  *----
  9.  * <sometime> JWTittsler    Original stuff.
  10.  * 13-Mar-1986 lmd        Some more functions.
  11.  */
  12.  
  13.  
  14. /*
  15.  * Cat string2 onto string1
  16.  *
  17.  */
  18. char *strcat(s1, s2)
  19. register char *s1;
  20. register char *s2;
  21. {
  22.     char *sptr;
  23.  
  24.     sptr = s1;
  25.     while (*s1++)        /* find the end of s1 */
  26.         ;
  27.     --s1;            /* back up so we point to the null */
  28.     while (*s1++ = *s2++)    /* tack on s2 */
  29.         ;
  30.     return sptr;
  31. }
  32.  
  33.  
  34. /*
  35.  * Copy string2 to string1
  36.  *
  37.  */
  38. char *strcpy(s1, s2)
  39. register char *s1;
  40. register char *s2;
  41. {
  42.     char *sptr;
  43.  
  44.     sptr = s1;
  45.     while (*s1++ = *s2++)
  46.     ;
  47.     return sptr;
  48. }
  49.  
  50.  
  51. /*
  52.  * Replace occurances of `c1' in the string `s'
  53.  * with `c2'.
  54.  *
  55.  */
  56. char *strrep(s, c1, c2)
  57. register char *s;
  58. register char c1;
  59. register char c2;
  60. {
  61.     char *sptr;
  62.  
  63.     sptr = s;
  64.     while (*s)
  65.     if(*s == c1)
  66.         *s++ = c2;
  67.         else ++s;;
  68.  
  69.     return sptr;
  70. }
  71.  
  72.  
  73. /*
  74.  * Return uppercase of `c'
  75.  *
  76.  */
  77. char toupper(c)
  78. char c;
  79. {
  80.     if(c >= 'a' && c <= 'z')
  81.     c -= 0x20;
  82.     return c;
  83. }
  84.  
  85.  
  86. /*
  87.  * Return `1' if `c' is an ascii space, tab, or newline.
  88.  *
  89.  */
  90. isspace(c)
  91. char c;
  92. {
  93.     if(c == 0x20 ||
  94.        c == '\t' ||
  95.        c == '\n') return 1;
  96.  
  97.     return 0;
  98. }
  99.  
  100.  
  101. /*
  102.  * Return `0' if the strings match, `1' if they don't;
  103.  * uppercase letters match their lowercase counterparts.
  104.  *
  105.  */
  106. strcmp(st1, st2)
  107. char *st1, *st2;
  108. {
  109.     register char *s1, *s2;
  110.  
  111.     s1 = st1;
  112.     s2 = st2;
  113.     while(*s1 && toupper(*s1) == toupper(*s2))
  114.     ++s1, ++s2;
  115.     return (*s1 != *s2);
  116. }
  117.